﻿// Inner Fire 游戏引擎库
// StopWatch - 简单秒表
//
// Copyright (c) 2025 by 尔西大帝. All rights reserved.
//
// 所属层级：基础结构层(1)
// 用于记录时间。
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2025-01-16

#pragma once

#include <chrono>
#include <iostream>
namespace ikit {

class Stopwatch {
public:
  // 构造函数，初始化时开始计时
  Stopwatch() { Start(); }

  // 开始计时
  void Start() { start_time = std::chrono::high_resolution_clock::now(); }

  // 结束计时
  void Stop() { end_time = std::chrono::high_resolution_clock::now(); }

  // 获取经过的毫秒数
  float GetElapsedMilliseconds() const {
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
        end_time - start_time);
    return static_cast<float>(duration.count());
  }

  // 获取经过的秒数
  float GetElapsedSeconds() const {
    auto duration =
        std::chrono::duration_cast<std::chrono::seconds>(end_time - start_time);
    return static_cast<float>(duration.count());
  }

  void Flush(const char* title);

private:
  std::chrono::high_resolution_clock::time_point start_time;
  std::chrono::high_resolution_clock::time_point end_time;
};

void start_stopwatch();
void close_stopwatch(const char* program_name);

} // namespace ikit